#include "gate_client_session.h"
#include "gate_event_handler.h"
#include "EndianCast.h"

namespace utility
{
namespace network
{
gate_client_session::gate_client_session(gate_sub_session * sub_session, uint32 remote_ip, uint32 local_ip, uint16 remote_port, uint16 local_port)
{
    sub_session_ = sub_session;
    event_handler_ = NULL;
    remote_ip_ = remote_ip;
    remote_port_ = remote_port;
    local_ip_ = local_ip;
    local_port_ = local_port;
}


gate_client_session::~gate_client_session(void)
{
}

uint32 gate_client_session::get_remote_ip()
{
    return remote_ip_;
}

std::string gate_client_session::get_remote_ip_as_string()
{
    struct in_addr addr;
    addr.s_addr = remote_ip_;
    return std::string(inet_ntoa(addr));
}

uint16 gate_client_session::get_remote_port()
{
    return remote_port_;
}

uint32 gate_client_session::get_local_ip()
{
    return local_ip_;
}

std::string gate_client_session::get_local_ip_as_string()
{
    struct in_addr addr;
    addr.s_addr = local_ip_;
    return std::string(inet_ntoa(addr));
}

uint16 gate_client_session::get_local_port()
{
    return local_port_;
}

void gate_client_session::set_event_handler(session_event_handler::pointer event_handler)
{
    event_handler_ = event_handler;
}

session_event_handler::pointer gate_client_session::get_event_handler()
{
    return event_handler_;
}

void gate_client_session::disconnect(bool bForce)
{
    sub_session_->disconnect(this);
}

void gate_client_session::send(void * message, size_t message_length)
{
    sub_session_->send(this, message, message_length);
}

void gate_client_session::reset_rcv_buf_size( uint32 nSize )
{

}

gate_sub_session * gate_client_session::get_sub_session()
{
    return sub_session_;
}

}
}


